//
//  XGL_LiveEndViewController.swift
//  XGamesLive
//
//  Created by ios on 2024/5/30.
//

import UIKit

class XGL_LiveEndViewController: UIViewController,CustomNavgationBar{
    
    private var liveTimeText: UILabel!
    var time: NSInteger = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        self.createCustomBackgroundView()
        self.createXglView()
        self.creatClearNavigationBar(title: "")
        self.convertTime()
    }
    

}

extension XGL_LiveEndViewController{
    private func convertTime(){
        if self.time < 60 {
            self.liveTimeText.text = "00:00:\(self.complementNum(count:self.time))"
        }else if self.time < 60 * 60{
            let min = self.time / 60
            let sec = self.time % 60
            self.liveTimeText.text = "00:\(self.complementNum(count:min)):\(self.complementNum(count:sec))"
        }else{
            let hou = self.time / (60 * 60)
            let min = (self.time % (60 * 60)) / 60
            let sec = self.time % 60
            self.liveTimeText.text = "\(self.complementNum(count:hou)):\(self.complementNum(count:min)):\(self.complementNum(count:sec))"
        }
    }
    private func complementNum(count: NSInteger)->String{
        if count < 10{
            return "0\(count)"
        }
        return count.description
    }
}

extension XGL_LiveEndViewController{
    private func createXglView(){
        let headerView = UIImageView().then { make in
            make.layerCornerRadius = 58.0
            make.clipsToBounds = true
            make.layerBorderColor = UIColor.hexColor("#80FFE6")
            make.layerBorderWidth = 1.0
            make.loadImageWithUrl(XGL_userDataManager.share.userHeader)
        }
        let nameText = UILabel().then { make in
            make.textColor = UIColor.white
            make.text = XGL_userDataManager.share.userName
            make.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
        }
        let endText = UILabel().then { make in
            make.textColor = UIColor.white
            make.text = "The live stream has ended"
            make.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
        }
        let bottomContentView = UIView().then { make in
            make.backgroundColor = UIColor.hexColor("#001310").withAlphaComponent(0.5)
            make.layerCornerRadius = 12.0
        }
        let timeTitleText = UILabel().then { make in
            make.text = "Live time"
            make.textColor = .white
            make.font = UIFont.pingfangSC_Regular(fontSize: 14.0)
        }
        self.liveTimeText = UILabel().then({ make in
            make.textColor = UIColor.hexColor("#80FFE6")
            make.font = UIFont.pingfangSC_Regular(fontSize: 22.0)
            make.textAlignment = .center
        })
        bottomContentView.addSubviews([timeTitleText,self.liveTimeText])
        self.view.addSubviews([headerView,nameText,endText,bottomContentView])
        
        headerView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(conversionWithScrennWidth(value: 125.0))
            make.width.height.equalTo(116.0)
        }
        nameText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(headerView.snp.bottom).offset(10.0)
        }
        endText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(nameText.snp.bottom).offset(8.0)
        }
        bottomContentView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(endText.snp.bottom).offset(45.0)
            make.width.equalTo(conversionWithScrennWidth(value: 169.0))
            make.height.equalTo(conversionWithScrennWidth(value: 88.0))
        }
        timeTitleText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(20.0)
        }
        self.liveTimeText.snp.makeConstraints { make in
            make.centerX.width.equalToSuperview()
            make.bottom.equalTo(-20.0)
        }
    }
}
